{  Statement: http://acmp.ru/?main=task&id_task=274
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
        i,j,x,y,ls,lt,tt:longint;
        s,t:string;
        a:array['0'..'9'] of boolean;
        f:boolean;
    
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(tt);
for i := 1 to tt do begin
    read(x, y);
    f := true;
    fillchar(a,sizeof(a),0);
    s := inttostr(x);
    t := inttostr(y);
    ls := length(s);
    for j := 1 to ls do
        a[s[j]] := true;
    lt := length(t);
    for j := 1 to lt do
        if not a[t[j]] then begin
            writeln('NO');
            f := false;
            break;
        end;
    for j := 1 to lt do
        a[t[j]] := false;
    for j := 1 to ls do
        if a[s[j]] then begin
            if f then writeln('NO');
            f := false;
            break;
        end;
    if f then writeln('YES');
end;
end.